package com.hospital.config;

import com.hospital.interceptor.AuthenticationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 通用配置类
 *
 * @Author yuhuan
 * @Date 2022/3/23
 */
@Configuration
@MapperScan("com.hospital.dao")
@EnableAspectJAutoProxy
@EnableTransactionManagement
public class HospitalConfig implements WebMvcConfigurer {
    /**
     * 将拦截器交给spring管理主要是为了让拦截器可以直接使用依赖注入
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginAuthentication());
    }

    /**
     * 身份验证拦截器
     */
    @Bean
    public AuthenticationInterceptor loginAuthentication() {
        return new AuthenticationInterceptor();
    }
}
